package nm.util.alarmclock;
import nm.widgets.ClockFace;

import java.awt.PopupMenu;
import java.awt.TrayIcon;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.event.ActionListener;

public class AlarmIcon extends TrayIcon {
	public static final int ICON_SIZE = 16; // default size for system tray icon
	public static final int IMG_TYPE = BufferedImage.TYPE_INT_RGB;
	
	public AlarmIcon(String tooltip, PopupMenu popup, ActionListener listener) {
		super(AlarmIcon.getIcon(), tooltip, popup);
		addActionListener(listener);
		setActionCommand(AlarmClock.CMD_OPTIONS);
	}
	
	public static BufferedImage getIcon() {
		BufferedImage icon = new BufferedImage(AlarmIcon.ICON_SIZE,
				AlarmIcon.ICON_SIZE, AlarmIcon.IMG_TYPE);
		
		Graphics2D g = icon.createGraphics();
		ClockFace clockItem = new ClockFace(AlarmIcon.ICON_SIZE);
		clockItem.paint(g);
		g.dispose();
		
		return icon;
	}
	
	public static BufferedImage getIcon(int hour, int minute) {
		BufferedImage icon = new BufferedImage(AlarmIcon.ICON_SIZE,
				AlarmIcon.ICON_SIZE, AlarmIcon.IMG_TYPE);
		
		Graphics2D g = icon.createGraphics();
		ClockFace clockItem = new ClockFace(AlarmIcon.ICON_SIZE);
		clockItem.moveHand(ClockFace.HAND_HOUR|ClockFace.HAND_MINUTE, 
				hour, minute, 0);
		clockItem.paint(g);
		g.dispose();
		
		return icon;
	}
	
}//end AlarmIcon
